package com.cuiyun97.controller.admin;

import com.cuiyun97.constant.DefaultConstant;
import com.cuiyun97.result.Result;
import com.cuiyun97.service.SetOssService;
import com.cuiyun97.service.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Slf4j
@RestController
@Api(tags = "通用接口")
@RequestMapping("/admin")
public class UploadController {

    // 文件上传
    @Resource
    private UploadService uploadService;

    /**
     * 文件上传
     *
     * @return
     */
    @PostMapping("/upload")
    @ApiOperation("文件上传")
    public Result upload(MultipartFile file) {

        // todo 自定义 bucket_name

        log.info("文件上传: {}", file);
        String url = uploadService.upload(file);
        return Result.success(url);
    }
}
